﻿using Microsoft.EntityFrameworkCore.Infrastructure;
using suirui.ZhuMu.Model;
using suirui.ZhuMu.Entity;
using suirui.ZhuMu.Entity.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace suirui.ZhuMu.Repositories
{
    public interface IBaseRepository<TEntity> where TEntity : class
    {
        DatabaseFacade Database { get; }
        mjgamesContext DbContext { get; }
        IQueryable<TEntity> Entities { get; }

        bool Any(Expression<Func<TEntity, bool>> whereLambd);
        long Count(Expression<Func<TEntity, bool>> predicate = null);
        Task<long> CountAsync(Expression<Func<TEntity, bool>> predicate = null);
        bool Delete(List<TEntity> entitys, bool isSaveChange = true);
        bool Delete(TEntity entity, bool isSaveChange = true);
        Task<bool> DeleteAsync(List<TEntity> entitys, bool isSaveChange = true);
        Task<bool> DeleteAsync(TEntity entity, bool isSaveChange = true);
        void Disposed();
        TEntity Get(Expression<Func<TEntity, bool>> predicate = null, bool isNoTracking = true);
        TEntity Get(object id);
        Task<TEntity> GetAsync(Expression<Func<TEntity, bool>> predicate = null, bool isNoTracking = true);
        Task<TEntity> GetAsync(object id);
        List<TEntity> GetList(Expression<Func<TEntity, bool>> predicate = null, string ordering = "", bool isNoTracking = true);
        Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> predicate = null, string ordering = "", bool isNoTracking = true);
        PageData<TEntity> GetPage(Expression<Func<TEntity, bool>> whereLambda, string ordering, int pageIndex, int pageSize, bool isNoTracking = true);
        Task<PageData<TEntity>> GetPageAsync(Expression<Func<TEntity, bool>> whereLambda, string ordering, int pageIndex, int pageSize, bool isNoTracking = true);
        Task<PageData<TEntity>> GetPageAsync<TKey>(Expression<Func<TEntity, bool>> whereLambda, Expression<Func<TEntity, TKey>> orderBy, int pageIndex, int pageSize, bool isOrder = true, bool isNoTracking = true);
        bool Insert(List<TEntity> entitys, bool isSaveChange = true);
        bool Insert(TEntity entity, bool isSaveChange = true);
        Task<bool> InsertAsync(List<TEntity> entitys, bool isSaveChange = true);
        Task<bool> InsertAsync(TEntity entity, bool isSaveChange = true);
        IQueryable<TEntity> Load(Expression<Func<TEntity, bool>> predicate = null, bool isNoTracking = true);
        Task<IQueryable<TEntity>> LoadAsync(Expression<Func<TEntity, bool>> predicate = null, bool isNoTracking = true);
        int SaveChanges();
        Task<int> SaveChangesAsync();
        bool Update(List<TEntity> entitys, bool isSaveChange = true);
        bool Update(TEntity entity, bool isSaveChange = true, List<string> updatePropertyList = null, bool modified = true);
        Task<bool> UpdateAsync(List<TEntity> entitys, bool isSaveChange = true);
        Task<bool> UpdateAsync(TEntity entity, bool isSaveChange = true, List<string> updatePropertyList = null, bool modified = true);
    }
}